﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BTGISWASECO.DataLayer;
using BTGISWASECO.BusinessEntities;
using BTGISWASECO.BusinessLayer;

public partial class PresentationLayer_DefaultTab : System.Web.UI.Page
{
    TramBomBLL bll = new TramBomBLL();
    DMHuongDongChayDAL DMHuongDongChayDal = new DMHuongDongChayDAL();
    TramBomEntities TramBomEntities = new TramBomEntities();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["DataTable"] == "")
                Response.Redirect("../default.aspx");
            for (int i = DateTime.Now.Year; i >= 1990; --i)
            {
                ListItem iteml = new ListItem(i.ToString(), i.ToString());
                DListNamXayDung.Items.Add(iteml);
            }
            TramBomEntities = bll.GetTramBomEntitiesByID();
            txtObjectID.Value = TramBomEntities.OBJECTID.ToString();

            txtIDTramBom.Text = TramBomEntities.IDTramBom;
            this.txtIDDMA.Text = TramBomEntities.IDDMA;
            this.txtIDDMZ.Text = TramBomEntities.IDDMZ;
            foreach (var itemtc in DMLoaiTramBomDAL.GetList())
            {
                if (TramBomEntities.LoaiTramBomText.ToString().Trim() == itemtc.MoTa.ToString().Trim())
                    TramBomEntities.LoaiTramBom = itemtc.Ma;
                ListItem iteml = new ListItem(itemtc.MoTa.ToString(), itemtc.Ma.ToString());
                DListLoaiTram.Items.Add(iteml);
            }
            DListLoaiTram.SelectedValue = TramBomEntities.LoaiTramBom.ToString();
            this.txtTenTram.Text = TramBomEntities.TenTram.ToString();
            this.txtMoTaViTri.Text = TramBomEntities.MoTaViTri.ToString();

            DListNamXayDung.SelectedValue = TramBomEntities.NamXayDung.ToString();
            this.dDTKhuDat.Text = TramBomEntities.DTKhuDat.ToString();

            this.dDTPhongBom.Text = TramBomEntities.DTPhongBom.ToString();

            this.dDTPVanHanh.Text = TramBomEntities.DTPVanHanh.ToString();
            this.txtTGHoatDong.Text = TramBomEntities.TGHoatDong.ToString();
            this.txtCheDoVanHanh.Text = TramBomEntities.CheDoVanHanh.ToString();
            this.dCongSuat.Text = TramBomEntities.CongSuat.ToString();
            this.nSoLuongBom.Text = TramBomEntities.SoLuongBom.ToString();
            this.dDoCaoSanBom.Text = TramBomEntities.DoCaoSanBom.ToString();
            this.txtTTSuDungDat.Text = TramBomEntities.TTSuDungDat.ToString();
            foreach (var itemntldv in DMLoaiDonViDAL.GetList())
            {
                if (TramBomEntities.DonViQLText != null)
                    if (TramBomEntities.DonViQLText.ToString().Trim() == itemntldv.MoTa.ToString().Trim())
                        TramBomEntities.DonViQL = itemntldv.Ma;
                ListItem iteml = new ListItem(itemntldv.MoTa.ToString(), itemntldv.Ma.ToString());
                DListDonViQL.Items.Add(iteml);
            }
            DListDonViQL.SelectedValue = TramBomEntities.DonViQL.ToString();

            this.txtTenTram.Text = TramBomEntities.SoNha.ToString();
            this.txtMaDuong.Text = TramBomEntities.MaDuong.ToString();
            this.txtMaPhuong.Text = TramBomEntities.MaPhuong.ToString();
            this.txtMaQuan.Text = TramBomEntities.MaQuan.ToString();

            foreach (var itemnttsd in DMTinhTrangSDDAL.GetList())
            {
                if (TramBomEntities.TinhTrangText.ToString().Trim() == itemnttsd.MoTa.ToString().Trim())
                    TramBomEntities.TinhTrang = itemnttsd.Ma;
                ListItem iteml = new ListItem(itemnttsd.MoTa.ToString(), itemnttsd.Ma.ToString());
                DListTTSD.Items.Add(iteml);
            }
            DListTTSD.SelectedValue = TramBomEntities.TinhTrang.ToString();

            foreach (var itemtsh in DMThuocSoHuuDAL.GetList())
            {
                if (TramBomEntities.ThuocSoHuuText.ToString().Trim() == itemtsh.MoTa.ToString().Trim())
                    TramBomEntities.ThuocSoHuu = itemtsh.Ma;
                ListItem iteml = new ListItem(itemtsh.MoTa.ToString(), itemtsh.Ma.ToString());
                DListThuocSoHuu.Items.Add(iteml);
            }
            DListThuocSoHuu.SelectedValue = TramBomEntities.ThuocSoHuu.ToString();

            this.nSoLanSuCo.Text = TramBomEntities.SoLanSuCo.ToString();
            this.txtNguoiCNC.Text = TramBomEntities.NguoiCNCuoi.ToString();
            this.txtNgayCNC.Text = TramBomEntities.NgayCNCuoi.ToString("dd/MM/yyyy");
            this.txtGhiChu.Text = TramBomEntities.GhiChu;
        }//ThuocSoHuu
    }
    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        TramBomEntities bk = new TramBomEntities();
        TramBomDAL TramBomDAL = new TramBomDAL();
        //TramBomEntities TramBomEntities = new TramBomEntities(Convert.ToInt32(DListDonViTC.SelectedValue = DListDonViTC.SelectedValue!=""?DListDonViTC.SelectedValue:"0"),
        //    Convert.ToInt32(DListDonViGS.SelectedValue = DListDonViGS.SelectedValue!=""?DListDonViGS.SelectedValue:"0"), this.txtNguoiCNC.Text, DateTime.Parse(this.txtNgayCNC.Text.ToString()), this.txtGhiChu.Text, this.txtMaHinhAnh.Text);
        TramBomEntities TramBomEntities = new TramBomEntities(Convert.ToInt32(txtObjectID.Value), txtIDTramBom.Text, this.txtIDDMA.Text, this.txtIDDMZ.Text,
                Convert.ToInt32(DListLoaiTram.SelectedValue = DListLoaiTram.SelectedValue != "" ? DListLoaiTram.SelectedValue : "0"),
                this.txtTenTram.Text, this.txtMoTaViTri.Text, Convert.ToInt32(DListNamXayDung.SelectedValue),
                Convert.ToDouble(this.dDTKhuDat.Text), Convert.ToDouble(this.dDTPhongBom.Text),
                Convert.ToDouble(this.dDTPVanHanh.Text), this.txtTGHoatDong.Text, this.txtCheDoVanHanh.Text,
                Convert.ToDouble(this.dCongSuat.Text), Convert.ToInt32(this.nSoLuongBom.Text),
                Convert.ToDouble(this.dDoCaoSanBom.Text), this.txtTTSuDungDat.Text,
                Convert.ToInt32(DListDonViQL.SelectedValue = DListDonViQL.SelectedValue != "" ? DListDonViQL.SelectedValue : "0"),
                this.txtTenTram.Text, this.txtMaDuong.Text, this.txtMaPhuong.Text, this.txtMaQuan.Text,
                Convert.ToInt32(DListTTSD.SelectedValue = DListTTSD.SelectedValue != "" ? DListTTSD.SelectedValue : "0"),
                Convert.ToInt32(DListThuocSoHuu.SelectedValue = DListThuocSoHuu.SelectedValue != "" ? DListThuocSoHuu.SelectedValue : "0"),
                Convert.ToInt32(this.nSoLanSuCo.Text), this.txtNguoiCNC.Text,DateTime.Parse(Request.Form.Get("txtNgayCNC")), this.txtGhiChu.Text);
        TramBomDAL.Update1(TramBomEntities);
        //TramBomDAL.Update(Convert.ToInt32(txtObjectID.Value), txtMaDoanOng.Text, txtDMA.Text, Convert.ToInt32(DListHDChay.SelectedValue), Convert.ToDouble(this.nChieuDai.Text));
     //   Response.Redirect("../default.aspx");
        ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script language='JavaScript'>alert('Cập nhật thành công'); window.location.href ='../Default.aspx';</script>");
    }
    protected void btnHuyBo_Click(object sender, EventArgs e)
    {
        Response.Redirect("../default.aspx");
    }
}